package com.kymjs.themvp.samples;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

/**
 * mainAbility
 */
public class MainAbility extends Ability implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_activity_main);
        findComponentById(ResourceTable.Id_button1).setClickedListener(this);
        findComponentById(ResourceTable.Id_button2).setClickedListener(this);
        findComponentById(ResourceTable.Id_button3).setClickedListener(this);
        findComponentById(ResourceTable.Id_button4).setClickedListener(this);
        findComponentById(ResourceTable.Id_button5).setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        Intent intent = new Intent();
        Intent.OperationBuilder operationBuilder = new Intent.OperationBuilder()
                .withDeviceId("").withBundleName("com.kymjs.themvp.samples");
        Operation operation = null;
        switch (component.getId()) {
            case ResourceTable.Id_button1:
                operation = operationBuilder.withAbilityName("com.kymjs.themvp.samples.demo1.SimpleActivity").build();
                break;
            case ResourceTable.Id_button2:
                operation = operationBuilder.withAbilityName("com.kymjs.themvp.samples.demo2.DemoActivity").build();
                break;
            case ResourceTable.Id_button3:
                operation = operationBuilder.withAbilityName("com.kymjs.themvp.samples.demo3.Demo3Activity").build();
                break;
            case ResourceTable.Id_button4:
                operation = operationBuilder.withAbilityName("com.kymjs.themvp.samples.demo4.ShellActivity").build();
                break;
            case ResourceTable.Id_button5:
                operation = operationBuilder.withAbilityName("com.kymjs.themvp.samples.demo6.Demo6Activity").build();
                break;
            default:
                break;
        }
        if (operation != null) {
            intent.setOperation(operation);
        }
        startAbility(intent);
    }
}
